package kr.saeildamil.androidforstudy2.ch23;

import kr.saeildamil.androidforstudy2.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.Toast;

public class AnimationListenerTest extends Activity {
	
	Button mBtn;
	Animation mAni01;
	Animation mAni02;
	Animation mAni03;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch23_animationlistenertest);
		
		mBtn = (Button) findViewById(R.id.ch23_animationlistenertest_btn);
		mBtn.setOnClickListener(new Button.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				mBtn.startAnimation(mAni01);
			}
		});
	
		mAni01 = AnimationUtils.loadAnimation(this, R.anim.rotate2);
		mAni02 = AnimationUtils.loadAnimation(this, R.anim.alpha2);
		mAni03 = AnimationUtils.loadAnimation(this, R.anim.scale2);
		
		mAni01.setAnimationListener(listener);
		mAni02.setAnimationListener(listener);
		mAni03.setAnimationListener(listener);
		
		/*mAni01.setAnimationListener(new AnimationListener() {
			public void onAnimationStart(Animation animation) {
				mBtn.startAnimation(mAni01);
			}
			public void onAnimationRepeat(Animation animation) {}
			public void onAnimationEnd(Animation animation) {
				mBtn.startAnimation(mAni02);
			}
			
		});
		
		mAni02.setAnimationListener(new AnimationListener() {
			public void onAnimationStart(Animation animation) {}
			public void onAnimationRepeat(Animation animation) {}
			public void onAnimationEnd(Animation animation) {}
		});
		
		mAni03.setAnimationListener(new AnimationListener() {
			public void onAnimationStart(Animation animation) {}
			public void onAnimationRepeat(Animation animation) {}
			public void onAnimationEnd(Animation animation) {
				String str = animation.toString();
				Toast.makeText(AnimationListenerTest.this, str, Toast.LENGTH_SHORT).show();
			}
		});*/
		
	}
		AnimationListener listener = new AnimationListener() {
			
			@Override
			public void onAnimationStart(Animation animation) {}
			public void onAnimationRepeat(Animation animation) {}
			public void onAnimationEnd(Animation animation) {
				if(animation.equals(mAni01)){
					mBtn.startAnimation(mAni02);
				}else if(animation.equals(mAni02)){
						mBtn.startAnimation(mAni03);
				}else if(animation.equals(mAni03)){
							Toast.makeText(AnimationListenerTest.this, "The End", Toast.LENGTH_SHORT).show();
						}
						}
									
			};
	}
		
	
